import java.util.Timer;

public class TimerTaskTest extends java.util.TimerTask {
	
	private static int tmp = 0;
	private static int max = 0;
	private static int loop = 0;
	
	protected TimerTaskTest(int max) {
		TimerTaskTest.max = max;
    }
	@Override
	public void run() {
		loop ++;
		System.out.println(tmp);
		if(loop == max){
			System.out.println("kill me");
			this.cancel();
			System.out.println("killed");
		}
	}
	
	public static class Test {
	public static void main(String[] args) {
			Timer timer = new Timer();
			timer.schedule(new TimerTaskTest(5), 5, 1000);		
			try {
			while(true){
				tmp += 1;
				Thread.sleep(1000);
			}		
			} catch (Exception ex) {
				ex.printStackTrace();
			}
		}
	}
}